package com.campus.dao.impl;

import com.campus.dao.EvaluationDao;
import com.campus.model.Evaluation;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * @desc: 评价数据访问实现类
 * @author: hjm
 * @date: 2024/11/22
 */
@Repository
public class EvaluationDaoImpl implements EvaluationDao {
    private final JdbcTemplate jdbcTemplate;

    public EvaluationDaoImpl(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    /**
     * 添加评价
     *
     * @param evaluation 评价对象
     * @return 受影响的行数
     */
    @Override
    public Integer addEvaluation(Evaluation evaluation) {
        String sql = "INSERT INTO t_teaching_evaluation (stu_in_class_id, grade, evaluation, evaluated_time, course_id, evaluator) " +
                "VALUES (?, ?, ?, ?, ?, ?)";

        // 使用 jdbcTemplate 执行插入操作
        return jdbcTemplate.update(sql,
                evaluation.getStuInClassId(),
                evaluation.getGrade(),
                evaluation.getEvaluation(),
                evaluation.getEvaluatedTime(),
                evaluation.getCourseId(),
                evaluation.getEvaluator());
    }
}